package com.hktf.corelib.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtil {

	/**
	 * @return
	 */
	public static long getLocalTimeInMillis(){
		Calendar calendar = Calendar.getInstance();
		long tickTime = calendar.getTimeInMillis();
		return tickTime;
	}
	
	public static String getLastDay(){
		Calendar   cal   =   Calendar.getInstance();
		  cal.add(Calendar.DATE, -1);
		  String yesterday = new SimpleDateFormat( "yyyy-MM-dd ").format(cal.getTime());
		  return yesterday;
	}
	
	/**
	 * @param date
	 * @return
	 */
	public static String formatDaySeconds(String date){
		Calendar c = Calendar.getInstance();
		try {
			c.setTime(new SimpleDateFormat("yyyy-MM-dd").parse(date));
		} catch (Exception e) {
			// TODO: handle exception
		}
		long ticktime = c.getTimeInMillis();
		return String.valueOf(ticktime);
	}
	/**
	 * @param s
	 * @return
	 */
	public static String formatDate( long s ){
		Date d = new Date(s);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String date = sdf.format(d);
		return date;
	}
	
	/**
	 * @param date
	 * @return
	 */
	public static String formatSeconds(String date){
		Calendar c = Calendar.getInstance();
		try {
			c.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date));
		} catch (Exception e) {
			// TODO: handle exception
		}
		long ticktime = c.getTimeInMillis();
		return String.valueOf(ticktime);
	}
}
